<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        form {
            width: 400px;
            margin: 100px auto;

        }

        .inp {
            width: 200px;
            height: 50px;
            border: 1px solid #ccc;
            outline: none;
            transition: all .5s ease-out;
            resize: none;
        }

        .inp::placeholder {
            font-size: 10px;
        }

        .box {
            display: flex;
        }

        .btn {
            background-color: rgb(34, 161, 193);
            height: 50px;
            line-height: 50px;
            text-align: center;
            vertical-align: middle;
            margin-left: 5px;
        }

        .texts {
            margin: 0;
            padding: 0;
            font-size: 12px;
            text-align: right;
            width: 200px;
            opacity: 0;
            transition: all .5s ease-out;
        }

        .inp:focus {
            height: 60px;
        }

        .box-liuyan {
            opacity: 0;
            transition: all .5s ease-out;
        }

        .wenzi {
            padding-left: 10px;
            border: 1px solid #ccc;
            display: flex;
            align-items: center;
        }
    </style>
</head>

<body>
    <form action="">
        <div class="box">
            <textarea class="inp" placeholder="发一条友善的评论" maxlength="200" rows="2"></textarea>
            <input type="button" value="发布" class="btn">
        </div>
        <p class="texts"><span class="tj">0</span>/200字</p>
        <div class="box-liuyan">
            <h3>评论:</h3>
            <div class="wenzi">
                <span class="user">我：</span>
                <p class="liuyan">这是我的留言</p>
            </div>
        </div>
    </form>
    <script>
        const textarea = document.querySelector('.inp')
        const tj = document.querySelector('.tj')
        const p = document.querySelector('.texts')
        const liuyan = document.querySelector('.liuyan')
        const boxliuyan = document.querySelector('.box-liuyan')
        textarea.addEventListener('input', function () {
            tj.innerHTML = this.value.length
        })
        textarea.addEventListener('focus', function () {
            p.style.opacity = 1;
        })
        textarea.addEventListener('blur', function () {
            p.style.opacity = 0;
        })
        textarea.addEventListener('keyup', function (even) {
            if (even.key === 'Enter') {
                // textarea.value.trim() !== ''
                // trim()去除空格的方法
                if (this.value.trim()) {
                    liuyan.innerHTML = this.value
                    boxliuyan.style.opacity = 1
                }
                this.value = ''
                tj.innerHTML = 0
            }
        })
    </script>
</body>

</html>